﻿//using HandyControl.Interactivity;
using MaterialDesignThemes.Wpf.Converters;
using Messenger.WinDialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Xaml.Behaviors;
using MaterialDesignThemes.Wpf.Internal;


namespace Messenger.Views
{
    /// <summary>
    /// BehaviorsAndTriggersView.xaml 的交互逻辑
    /// </summary>
    public partial class BehaviorsAndTriggersView : UserControl,IDialogView
    {
        public BehaviorsAndTriggersView()
        {
            InitializeComponent();
        }

        public event IDialogView.HandleResult? HandleResultEvent;

        public void Dispose()
        {
            return;
        }

        public object? GetResult()
        {
            throw new NotImplementedException();
        }

        public void HadleResult(MessageBoxResult result)
        {
            HandleResultEvent?.Invoke(result);
        }
    }

    /// <summary>
    /// Border行为
    /// </summary>
    public class MyBehavior : Behavior<Border>
    {
        protected override void OnAttached()
        {
            AssociatedObject.MouseMove += (object o,MouseEventArgs e) => AssociatedObject.Background = Brushes.Orange;
            AssociatedObject.MouseLeave += (object o, MouseEventArgs e) => AssociatedObject.Background = Brushes.Green;
        }
        protected override void OnDetaching()
        {

        }

    }

    /// <summary>
    /// 清除行为
    /// </summary>
    public class TextClearBehavior : Behavior<Button> 
    {
        public TextBox Target
        {
            get { return (TextBox)GetValue(TargetProperty); }
            set { SetValue(TargetProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Target.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TargetProperty =
            DependencyProperty.Register("Target", typeof(TextBox), typeof(TextClearBehavior), new PropertyMetadata(null));

        protected override void OnAttached() 
        {
            AssociatedObject.Click += ButtonClick;
        }

        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            Target?.Clear();
        }
    }

    public class WheelBehavior : Behavior<TextBox> 
    {
        protected override void OnAttached()
        {
            AssociatedObject.MouseWheel += MouseWheel; 
        }

        private void MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (e.Delta > 0) 
            {
                AssociatedObject.Text = int.Parse(e.Delta.ToString()+5).ToString();
            }
        }
    }
}
